# -*- coding: utf-8 -*-
# @Time    : 2023/9/25 22:03
# @Author  : MinChess
# @File    : main.py
# @Software: PyCharm
import os
import sys
from PySide6.QtCore import QFile, QIODevice, Slot
from PySide6.QtUiTools import QUiLoader
from PySide6.QtWidgets import QApplication, QMainWindow, QMessageBox, QPushButton
import timeit
import networkx as nx


# 定义主窗口类
from path_planner.astar_path_planner_v1 import AstarPathPlannerV1


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        # 加载UI文件
        loader = QUiLoader()
        ui_file = QFile("../res/ui/main.ui")
        if not ui_file.open(QIODevice.ReadOnly):
            print("无法打开UI文件")
            sys.exit(-1)

        # 加载UI文件并实例化为窗口对象
        self.window = loader.load(ui_file)

        # 关闭UI文件
        ui_file.close()


if __name__ == "__main__":
    # app = QApplication([])
    # main_window = MainWindow()
    # main_window.window.show()
    # app.exec()
    time_start = timeit.default_timer()
    astar_planner = AstarPathPlannerV1(os.path.join(os.getcwd(),"src","data.xlsx"))
    time_milestone1 = timeit.default_timer()
    astar_path1 = astar_planner.plan_path("成都", "北京西")
    time_milestone2 = timeit.default_timer()
    astar_path2 = astar_planner.plan_path("成都", "广州")
    time_milestone3 = timeit.default_timer()
    # Use Dijkstra's algorithm to find the shortest path
    dijkstra_path1 = nx.dijkstra_path(astar_planner.graph, source="成都", target="北京西")
    time_milestone4 = timeit.default_timer()
    dijkstra_path2 = nx.dijkstra_path(astar_planner.graph, source="成都", target="广州")
    time_milestone5 = timeit.default_timer()
    print("time1:", time_milestone1 - time_start)
    print("time2:", time_milestone2 - time_milestone1)
    print("time3:", time_milestone3 - time_milestone2)
    print("time4:", time_milestone4 - time_milestone3)
    print("time5:", time_milestone5 - time_milestone4)
    print("AStar path from 成都 to 北京西:", astar_path1)
    print("Dijkstra path from 成都 to 北京西:", dijkstra_path1)